#include <stdio.h>
struct ListNode {
    int val;
    struct ListNode* next;
};
typedef struct ListNode ListNode;
struct ListNode* reverseList(struct ListNode* head)
{
    if (!head)
        return NULL;

    ListNode* prev = NULL;
    ListNode* cur = head;
    ListNode* rear = cur->next;

    while (cur != NULL)
    {
        rear = cur->next;
        cur->next = prev;
        prev = cur;
        cur = rear;
    }

    return prev;

}